"""
内容:将购买商品记录封装成一个类
作者:Zhou
"""

"""前置条件,已经登录成功"""
#引入
from ECshop.common.base import create_browser,Base,create_browser_op
import time


class PageBuyRecord01(Base):
    #属性
    url='http://localhost:8080/ecshop/user.php'
    first=('link text','首页')
    camera=("xpath",("//img[@src='images/201605/thumb_img/72_thumb_G_1462956048008.jpg']"))
    buy=('xpath',("//img[@src='themes/default/images/buybtn1.png']"))
    pay=('xpath',("//img[@src='themes/default/images/checkout.gif']"))
    put_in=('xpath',("//input[@src='themes/default/images/bnt_subOrder.gif']"))
    record_username=("xpath",("//div[@class='box_1']/div/table/tbody/tr[2]/td[1]"))
    record_number=("xpath",("//div[@class='box_1']/h3[1]/font"))

    #方法
    #打开网页
    def page_buy_record_web(self):
        self.base_open_web(self.url)
    #点击首页
    def page_buy_record_first(self):
        self.base_click(self.first)
    #点击智能相机
    def page_buy_record_camera(self):
        self.base_click(self.camera)
        time.sleep(2)
    #立即购买
    def page_buy_record_buy(self):
        self.base_click(self.buy)
    #立即结算
    def page_buy_record_pay(self):
        self.base_click(self.pay)
    #提交订单
    def page_buy_record_put_in(self):
        self.base_click(self.put_in)
    # 点击首页
    def page_buy_record_first1(self):
        self.base_click(self.first)
    # 点击智能相机
    def page_buy_record_camera1(self):
        self.base_click(self.camera)
        time.sleep(2)
    #获取最新购买的用户名
    def page_buy_record_username(self):
        result=self.base_get_text(self.record_username)
        return result
    #获取最新成交数量
    def page_buy_record_number(self):
        result=self.base_get_text(self.record_number)
        return result
    #关闭网页
    def page_buy_record_quit(self):
        self.base_quit()

if __name__ == '__main__':
    c1=PageBuyRecord01(create_browser_op(r'C:\Users\lenovo\AppData\Local\Google\Chrome\User Data'))
    c1.page_buy_record_web()
    c1.page_buy_record_first()
    c1.page_buy_record_camera()
    c1.page_buy_record_buy()
    c1.page_buy_record_pay()
    c1.page_buy_record_put_in()
    c1.page_buy_record_first1()
    c1.page_buy_record_camera1()
    print(c1.page_buy_record_username())
    print(c1.page_buy_record_number())
    # c1.page_buy_record_quit()